import '../public.dart';
import '../views/root/root.dart';
import '../views/group/list.dart';
import '../views/about/view.dart';
import '../views/login/view.dart';
import '../views/regist/view.dart';
import '../views/setting/view.dart';
import '../views/reset_password/view.dart';
import '../views/add_bank_card/view.dart';
import '../views/withdraw/view.dart';
import '../views/sell_gift_card/view.dart';
import '../views/sell_gift_card_detail/view.dart';
import '../views/top_gift_cards/view.dart';
import '../views/splash/view.dart';
import '../views/create_pin/view.dart';
import '../views/change_password/view.dart';
import '../views/change_pin/view.dart';
import '../views/security/view.dart';

class RouteHub {
  /// 是否需要登录授权
  bool authorize;
  late Widget Function(Object?) builder;

  RouteHub(dynamic builder, {this.authorize = false}) {
    if (builder is Widget Function(Object?)) {
      this.builder = builder;
    } else {
      this.builder = (_) => builder;
    }
  }
}

class Routers {
  static String splash = '/';
  static String main = 'main';
  static String login = 'login';
  static String regist = 'regist';
  static String form = 'form';
  static String webView = 'webView';
  static String setting = 'setting';
  static String types = 'types';
  static String groupList = 'groupList';
  static String about = 'about';
  static String feedBack = 'feedBack';
  static String resetPassword = 'resetPassword';
  static String addBankCard = 'add_bank_card';
  static String createPin = 'create_pin';
  static String changePassword = 'change_password';
  static String changePin = 'change_pin';
  static String withdraw = 'withdraw';
  static String sellGiftCard = 'sell_gift_card';
  static String sellGiftCardDetail = 'sell_gift_card_detail';
  static String topGiftCards = 'top_gift_cards';
  static String security = 'security';

  static Map<String, RouteHub> routeDeictionary = {
    splash: RouteHub(const SplashPage()),
    main: RouteHub((arg) => TabNavigator(arg), authorize: true),
    groupList: RouteHub((arg) => GroupList(arg)),
    about: RouteHub(const AboutUs()),
    login: RouteHub(const LoginPage()),
    regist: RouteHub(const RegistPage()),
    setting: RouteHub(const SettingPage()),
    resetPassword: RouteHub(const ResetPasswordPage()),
    addBankCard: RouteHub(const AddBankCardPage()),
    createPin: RouteHub(const CreatePinPage()),
    changePassword: RouteHub(const ChangePasswordPage()),
    changePin: RouteHub(const ChangePinPage()),
    withdraw: RouteHub(const WithdrawPage()),
    sellGiftCard: RouteHub(const SellGiftCardPage()),
    sellGiftCardDetail: RouteHub(
      (arg) => SellGiftCardDetailPage(
        cardTypeId: arg is Map<String, dynamic> ? arg['cardTypeId'] as int : 0,
        cardTypeName: arg is Map<String, dynamic>
            ? arg['cardTypeName'] as String
            : '',
        category: arg is Map<String, dynamic>
            ? arg['category'] as SysGiftCardCategoryEntity?
            : null,
      ),
    ),
    topGiftCards: RouteHub(const TopGiftCardsPage()),
    security: RouteHub(const SecurityPage()),
  };
}
